package net.googlecode.exigenlab.task3;

import net.googlecode.exigenlab.task3.calculator.Calculator;
import net.googlecode.exigenlab.task3.calculator.SalaryCalculatorFactory;
import net.googlecode.exigenlab.task3.model.Boss;
import net.googlecode.exigenlab.task3.model.Employee;
import net.googlecode.exigenlab.task3.model.Manager;
import net.googlecode.exigenlab.task3.model.Person;

import java.math.BigDecimal;

/**
 * Main application for calculating salary for person
 */
public class SalaryApp {
    private static final BigDecimal BOSS_TAX = new BigDecimal(500);
    private static final BigDecimal MANAGER_TAX = new BigDecimal(250);
    private static final BigDecimal EMPLOYEE_TAX = new BigDecimal(125);

    public static void main(String[] args) {
        Manager boss = createBoss();
        System.out.println(String.format("%s >> %s: $%s", boss.getType(), boss.toString(),
                calculateSalary(boss, BOSS_TAX)));

        Manager manager = createManager();
        System.out.println(String.format("%s >> %s: $%s", manager.getType(), manager.toString(),
                calculateSalary(manager, MANAGER_TAX)));

        Manager employee = createEmployee();
        System.out.println(String.format("%s >> %s: $%s", employee.getType(), employee.toString(),
                calculateSalary(employee, EMPLOYEE_TAX)));

    }

    private static BigDecimal calculateSalary(Manager person, BigDecimal tax) {
        Calculator salaryCalculator = SalaryCalculatorFactory.getCalculator(person);
        salaryCalculator.setTax(tax);
        return salaryCalculator.calculateSalary(person);
    }

    public static Manager createManager() {
        Manager manager = new Manager();
        manager.setFirstName("Ivan");
        manager.setLastName("Ivanov");
        manager.setAge(30);
        manager.setPerHour(true);
        manager.setBonus(false);
        manager.setRate(new BigDecimal(25));

        return manager;
    }

    public static Boss createBoss() {
        Boss boss = new Boss();
        boss.setFirstName("Petr");
        boss.setLastName("Petrov");
        boss.setAge(35);
        boss.setBonusAmount(new BigDecimal(1000));
        boss.setRate(new BigDecimal(50));

        return boss;
    }

    public static Employee createEmployee() {
        Employee employee = new Employee();
        employee.setFirstName("Semen");
        employee.setLastName("Semenov");
        employee.setAge(55);
        employee.setBonus(true);
        employee.setBonusAmount(new BigDecimal(1500));
        employee.setPerHour(true);
        employee.setRate(new BigDecimal(8));

        return employee;
    }
}
